﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_NH.DB_Map.ZJK
{
    using NHibernate;
    using NHibernate.Mapping.ByCode;
    using NHibernate.Mapping.ByCode.Conformist;

    using DB_NH.DB_Model.ZJK;

    public class ZJ_category_map : EntityMapping<ZJ_category>
    {
        public ZJ_category_map()
        {
            Property(x => x.category_level, map =>
            {
                map.Column(ZJ_category.Columns.category_level);
            });

            Property(x => x.category_code, map =>
            {
                map.Column(ZJ_category.Columns.category_code);
                map.Length(20);
            });

            Property(x => x.category_name, map =>
            {
                map.Column(ZJ_category.Columns.category_name);
                map.Length(100);
            });

            Property(x => x.is_leaf, map =>
            {
                map.Column(ZJ_category.Columns.is_leaf);
            });

            Property(x => x.category_path, map =>
            {
                map.Column(ZJ_category.Columns.category_path);
            });

            //上一级分类
            ManyToOne(x => x.pre_category, map =>
            {
                map.Column(ZJ_category.Columns.pre_category_id);
                map.NotNullable(false);
                map.Cascade(Cascade.None);
            });

            Bag(x => x.sub_categorys, bag =>
            {
                bag.Key(km => km.Column(ZJ_category.Columns.pre_category_id));
                bag.Cascade(Cascade.None);
                bag.Inverse(false);
            }, act => act.OneToMany());

            Bag(x => x.zj_experts, bag => { }, act => act.ManyToMany());

            Table(ZJ_category.TableName);
        }
    }
}
